安装 Golang
- 安装
 
1  | brew install go  | 
安装 direnv 方便随目录切换环境变量
https://github.com/direnv/direnv
1. 安装
1  | brew install direnv  | 
2. 设置环境变量
~/.bashrc或者~/.zshrc
1  | eval "$(direnv hook zsh)"  | 
3. 环境变量立即生效
source ~/.bashrc 或者 source ~/.zshrc
4. 配置基于项目目录的环境变量
项目目录
.envrc
1  | export GOPATH=`pwd`:$GOPATH  | 
5. 使 .envrc 生效
为安全考虑, 每次更改 .envrc 都需要手动启用生效
1  | direnv allow  | 
使用包管理工具 glide, dep 进行包管理
1. 安装
1  | brew install glide dep  | 
2. 基本使用
1  | glide create(init)  | 
1  | dep init  | 
查看一些最佳找实践
https://github.com/avelino/awesome-go
官方依赖不翻墙下载失败?
1. 在 https://github.com/golang 中找到对应包, 克隆到本地…
1  | echo "tools build playground sys net crypto debug text arch tour mobile vgo exp review time scratch image perf lint sync" | \  | 
2. 定义 Mirror 镜像
参考: https://zhuanlan.zhihu.com/p/31402004
3. 自行翻墙
在 .envrc 中添加本地翻墙:
1  | export http_proxy=socks5://127.0.0.1:1086  | 
参考: https://www.cnblogs.com/tonglin0325/p/9153452.html
使用 gin 作为基础服务框架
https://github.com/gin-gonic/gin
使用自动发现重新编译脚本
https://github.com/githubnemo/CompileDaemon
安装: go get github.com/githubnemo/CompileDaemon
使用: ${GOBIN}/CompileDaemon -directory=project_dir/ -command=run_after_build -exclude-dir=.git -exclude=.#*